import { h } from 'vue';
import { NAvatar, NSwitch, NTag } from 'naive-ui';
export const columns = [
  {
    title: '用户ID',
    key: 'id',
    width: 60,
  },
  {
    title: '用户名',
    key: 'username',
    width: 80,
  },
  {
    title: '昵称',
    key: 'nickName',
    width: 100,
  },

  {
    title: '类型',
    key: 'userType',
    width: 70,
    render(row) {
      if (row.userType == 1) {
        return h(
          NTag,
          {
            style: {
              marginRight: '6px',
            },
            type: 'error',
            bordered: false,
          },
          {
            default: () => '管理员',
          }
        );
      } else {
        return h(
          NTag,
          {
            style: {
              marginRight: '6px',
            },
            type: 'info',
            bordered: false,
          },
          {
            default: () => '普通用户',
          }
        );
      }
    },
  },
  {
    title: '状态',
    key: 'status',
    width: 60,
    render(row) {
      if (row.status == '1') {
        row.status = true;
        return h(NSwitch, {
          round: true,
          value: row.status,
          onUpdateValue: () => handleChangeState(row),
        });
      } else {
        row.status = false;
        return h(NSwitch, {
          round: true,
          value: row.status,
          onUpdateValue: () => handleChangeState(row),
        });
      }
    },
  },
  {
    title: '头像',
    key: 'avatar',
    width: 40,
    render(row) {
      return h(NAvatar, {
        size: 38,
        src: row.avatar,
      });
    },
  },
  {
    title: '手机号',
    key: 'phoneNumber',
    width: 100,
  },
  {
    title: '邮箱',
    key: 'email',
    width: 100,
  },
  {
    title: '性别',
    key: 'sex',
    width: 60,
    render(row) {
      if (row.sex == 1) {
        return h(
          NTag,
          {
            style: {
              marginRight: '6px',
            },
            type: 'info',
            bordered: false,
          },
          {
            default: () => '男',
          }
        );
      } else if (row.sex == 0) {
        return h(
          NTag,
          {
            style: {
              marginRight: '6px',
            },
            type: 'error',
            bordered: false,
          },
          {
            default: () => '女',
          }
        );
      } else {
        return h(
          NTag,
          {
            style: {
              marginRight: '6px',
            },
            bordered: false,
          },
          {
            default: () => '未知',
          }
        );
      }
    },
  },
  {
    title: '创建时间',
    key: 'createTime',
    width: 120,
  },
  {
    title: '修改时间',
    key: 'updateTime',
    width: 120,
  },
];

function handleChangeState(row) {
  row.state = !row.state;
}
